<template>
    <view class="content">
        <van-nav-bar :title="navBarTitle" left-arrow @click-left="onClickLeft" class="navBar">
        </van-nav-bar>
        <view class="page">
            <view class="pageTitle">{{navBarTitle }}</view>
            <view class="date-container" v-if="type=='hasIn' || type == 'hasOut'">
                <view class="date-prev pr24" @tap="prevDate">
                    <van-icon name="arrow-left" />
                </view>
                <view class="date-display" @tap="showCalendar">
                    <img src="https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/calendarIcon.png" alt="">
                    <text>{{ displayDate }}</text>
                </view>
                <view class="date-next pl24" @tap="nextDate"> <van-icon name="arrow" />  </view>
            </view>
            <scroll-view class="scroll-content" scroll-y :lower-threshold="80" @scroll="scrollPage"
                show-scrollbar="false">
                <view class="expressListBox" v-if="resultList && resultList.length > 0">
                    <!-- <merchantList :resultList="resultList" @checkbox-change="handleCheckboxChange"
                        @handlechecked="handlechecked" :check-all="checkAll" @showMoreAction="showMoreAction"
                        @submitSinglePackage="submitSinglePackage"
                        @cancelStockOut = "cancelStockOut"
                        :type="type" :loading="loading" :finished="finished" ></merchantList> -->
                    <returnInOrOutList :resultList="resultList" @checkbox-change="handleCheckboxChange"
                        @handlechecked="handlechecked" :check-all="checkAll" @showMoreAction="showMoreAction"
                        @submitSinglePackage="submitSinglePackage"
                        @cancelStockOut = "cancelStockOut"
                        :type="type" :loading="loading" :finished="finished"></returnInOrOutList>
                </view>
                <view class="noPackagewrapper" v-else>
                    <van-empty class="custom-image"
                        image="https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/emptyPackage.png"
                        description="暂无包裹信息" />
                </view>
            </scroll-view>
        </view>
        <template v-if="type !== 'hasOut' && showBottomBtn">
            <view class="nav_box">
                <van-submit-bar price="" :button-text="buttonText" button-type="warning" @submit="allTakeInOrOut" :disabled="isSubmiting" :class="{ 'is-submiting': isSubmiting }">
                    <view style="display: flex; align-items: center;" class="delete">
                        <van-checkbox checked-color="#FF6203" v-model="checkAll" :label-disabled="false"
                            @click="onChangeItem('多选')" @change="handleCheckAll" use-icon-slot>
                            <image @change="handleCheckAll" slot="icon" class="checked-img"
                                :src="checkAll ? activeIcon : inactiveIcon" />
                        </van-checkbox>
                        <view class="selectedNum" @click="onChangeItem('多选')">已选（{{ selectedRowKeys.length }}）</view>
                    </view>
                </van-submit-bar>
            </view>
        </template>
        <van-toast id="van-toast" />
        <van-dialog id="van-dialog" confirm-button-color='#ff6203' />
        <moreActionsPopup :showPopup="showActSheet" :packageInfo="packageInfo" @onCloseActions="onCloseActions" :action="moreActions"
            @toStockOut="toStockOut" @toPhotoOut="toPhotoOut"
            :loading="loading" :finished="finished" @onConfirmCancel="onConfirmCancel"></moreActionsPopup>
       <calendar :show="showCalendarPopup" @onCloseCalendar="onCloseActions" :sign="'StockOut'" @onConfirmStockOutCalendar="onConfirmStockOutCalendar" :pageTop="pageTop"></calendar>
    </view>
</template>
<script>
import Toast from '@/wxcomponents/vant/toast/toast'
import merchantList from '@/mycomponents/merchant/merchantList.vue'
import returnInOrOutList from '@/mycomponents/merchant/returnInOrOutList.vue'
import moreActionsPopup from '@/mycomponents/merchant/moreActionsPopup.vue'
import calendar from '@/mycomponents/merchant/calendar.vue'
import Dialog from '@/wxcomponents/vant/dialog/dialog'
import {getSelfPickupListApi,handleInboundApi,handleOutboundApi,cancelSelfPickupApi} from '@/api/merchant'

export default {
    components:{
        merchantList,
        returnInOrOutList,
        moreActionsPopup,
        calendar
    },
    props: {
        show: {
            type: Boolean,
            default: () => false
        },
        popupParams: {
            type: Object,
            default: () => ({})
        }
    },
    data () {
        return {
            navBarTitle:'待入库',
            scrolling:false,
            // searchPlaceholder: 'Enter tracking number',
            // searchButton: 'Search',
            // tabsList: [
            //     {
            //         key: '0',
            //         tabsName: '手机号'
            //     },
            //     {
            //         key: '1',
            //         tabsName: '运单号'
            //     },
            //     {
            //         key: '2',
            //         tabsName: '取件码'
            //     },
            //     {
            //         key: '3',
            //         tabsName: '姓名'
            //     },
            // ],
            // current:0, //当前选中的tab
            status: {
                notOutbound: 'Not Outbound',
                outbound: 'Outbound'
            },
            searchValue: '',
            tabActive: 0,
            // expressList: [
            //     { phone: '198****1000', name: '刘*而', status: 1 },
            //     { phone: '185****1000', name: '张桐二', status: 1 },
            //     { phone: '15232651000', name: '孙*俪', status: 0 },
            //     { phone: '18546781000', name: '刘*娥', status: 0 }
            // ],
            phoneCount:4, //同名字不同手机数量
            packagesCount:2, //未出库包裹数量
            resultList:[
                // {
                //     wayBillNo:'1234567890124',
                //     pickupCode:'2204',
                //     status:'hasOut',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     userName:"张伟",
                //     phone:"18546781000",
                // },
                // {
                //     wayBillNo:'1234567890123',
                //     pickupCode:'2203',
                //     status:'awaitIn',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     userName:"张伟",
                //     phone:"18546781000",
                // },
                // {
                //     wayBillNo:'1234567890125',
                //     pickupCode:'2205',
                //     status:'hasIn',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     userName:"张伟",
                //     phone:"18546781000",
                // },
                // {
                //     wayBillNo:'1234567890127',
                //     pickupCode:'2207',
                //     status:'returnAwaitIn',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     userName:"张伟",
                //     phone:"18546781000",
                // },
                // {
                //     wayBillNo:'1234567890129',
                //     pickupCode:'2209',
                //     status:'returnAwaitOut',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     userName:"张伟",
                //     phone:"18546781000",
                // },
                // {
                //     wayBillNo:'1234567890126',
                //     pickupCode:'2206',
                //     status:'hasOut',
                //     address:'北京市海淀区',
                //     time:'2023-10-10 10:10:10',
                //     userName:"张伟",
                //     phone:"18546781000",
                // }
            ],

            showBottomBtn: false, // 是否显示底部按钮
            singleList:[],// 单个入库
            checkAll: false, // 全选状态
            selectedRowKeys: [], // 已选择的数据的id
            selectedRows: [], // 已选择的数据
            checked: [],
            inactiveIcon:
                'https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/notChecked1126.png',
            activeIcon:
                'https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/goodsChecked1126.png',
            disabledIcon: 'https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/disabledIcon.png',
            isShowBlue: false,
            showActSheet: false, // 控制动作面板的显示
            moreActions: [
                { name: '转上门', color: '#ff4949' },
                { name: '取消入库', color: '#1989fa' },
            ],
            type: 'hasIn', // 页面类型，默认为入库
            statusNumber: 1, // 状态数字，默认为1
            displayDate: '2025.03.31',
            currentDate: undefined,
            showCalendarPopup: false,
            buttonText: '一键入库',
            navTitles :{
                'await': '待入库',
                'hasIn': '已入库', 
                'abnormal': '异常',
                'hasOut': '已出库',
                'PENDING': '滞留',
                'currentStock':'当前库存',
                'returnAwaitIn':'退货待入库',
                'returnAwaitOut':'退货待出库'
            },
            buttonTexts : {
                'await': '一键入库',
                'abnormal': '一键入库',
                'hasIn': '一键出库',
                'hasOut': '取消出库',
                'PENDING': '一键出库',
                'currentStock':'一键出库',
                'returnAwaitIn':'退货入库',
                'returnAwaitOut':'退货出库'
            },
            statusMap:{
                1: "TO_BE_STORED",
                2: "STORED",
                3: "OUTBOUND",
                4: "ABNORMAL",
                5: "TO_BE_RETURN_STORED",
                6: "RETURN_TO_BE_OUTBOUND",
                7: "CURRENT_INVENTORY",
                8: "PENDING"
            },
//             TO_BE_STORED(1, "待入库"),
//     STORED(2, "已入库"),
// //    RETURN_STORED(10, "退货已入库"),
//     OUTBOUND(3, "已出库"),
//     RETURN_OUTBOUND(9, "退货已出库"),
//     ABNORMAL(4, "异常"),
//     TO_BE_RETURN_STORED(5, "待退货入库"),
//     RETURN_TO_BE_OUTBOUND(6, "退货待出库"),
//     CURRENT_INVENTORY(7, "当前库存"),
//     PENDING(8, "滞留");
            pageTop:'',
            menuButtonTop:'',
            pageNum:1,
            pageSize:10,
            total:0,
            totalPage:0,
            loading: false,
            finished: false,
            packageInfo:undefined,
            isSubmiting: false // 控制提交状态
        }
    },

    computed: {
    },

    watch:{
        resultList: {
            immediate: true,
            handler(val) {
                console.log(val)
                if (!val || val.length == 0) {
                    this.showBottomBtn = false
                    return false
                }else{
                    this.showBottomBtn = true
                }
                var i = 0
                this.resultList.forEach(item => {
                    if (item.isChecked === true) {
                        i++
                    }
                    this.checkAll = i === this.resultList.length
                })
            },
            deep: true
        },
        checked: {
            handler (val) {
                console.log(val, 'newName')
            }
        },
        selectedRowKeys: {
            handler (val) {
                console.log(val, 'selectedRowKeys')
                if (val.length > 0) {
                    this.isShowBlue = true // 标记为正常的按钮  深蓝色
                } else {
                    this.isShowBlue = false // 标记为正常的按钮  浅蓝色
                }
            }
        },
        selectedRows: {
            handler (val) {
                console.log(val, 'selectedRows')
            }
        },

    },
    onLoad (options) {
        if (options) {
            console.log(options,options.type)
            this.type = options.type // 获取页面类型 PENDING
            this.navBarTitle = this.navTitles[options.type] || '未知状态'
            this.buttonText = this.buttonTexts[options.type] || '操作'
            if (options.statusNumber) {
                // 转换为数字类型
                this.statusNumber = Number(options.statusNumber); 
            }
            console.log('获取到的 statusNumber:', this.statusNumber);
     
        }
        // const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
        // console.log('胶囊按钮高度：', menuButtonInfo.height,'胶囊按钮top：', menuButtonInfo.top,menuButtonInfo);
        // this.menuButtonTop = menuButtonInfo.top
        // this.pageTop='padding-top:'+ ( this.menuButtonTop + menuButtonInfo.height ) +'px' 
        // console.log(this.pageTop)
    },
    onReady () {
        // this.resultList.forEach(ele => {
        //     this.$set(ele, 'isChecked', false)
        //     ele.statusText = this.getStatusText(ele.status)
        // });
        // 确保日期在页面准备好时更新
        this.displayDate = this.formattedDate(new Date());
        
        const query = uni.createSelectorQuery().in(this)
        query.select('.navBar').boundingClientRect(data => {
            console.log(data.height, 'data.height--')// 这个就是距离顶部的高度
            const height = data?.height || 90
            this.pageTop='padding-top:'+ height +'px' 
        }).exec()
     },

     onShow() {
        this.currentDate = this.formattedDateStr(new Date());
        this.getSelfPickupList()
     },
    methods: {
        // 滑动
        scrollPage(e) {
            console.log(e.detail.scrollTop, this.scrolling)
            if (e.detail.scrollTop > 25 && !this.scrolling) {
                this.scrolling = true
            } else if ((e.detail.scrollTop <= 25 && this.scrolling) || (e.detail.scrollTop <= 25 && !this.scrolling)) {
                this.scrolling = false
            }
        },
        // 返回键
        onClickLeft() {
            uni.redirectTo({
                url: '/pages/merchant/index'
            })
        },
        // 新增加载更多方法
        loadMore() {
            if (!this.finished) {
                this.getSelfPickupList()
            }
        },
        getStatusText(status) {
            const statusMap = {
                'hasOut': '已出库',
                'awaitIn': '待入库',
                'hasIn': '已入库',
                'returnAwaitIn': '退货待入库',
                'returnAwaitOut': '退货待出库'
            }
            return statusMap[status] || '未知状态'
        },
        // 点击确认按钮后的提示弹窗 中对应的文字
        getTipsStatusText(status) {
            const statusMap = {
                'await': '入库',
                'hasIn': '出库', 
                'returnAwaitIn': '退件入库',
                'returnAwaitOut': '退件出库',
                'PENDING': '出库',
                'abnormal':'入库',
                'hasOut':'取消出库',
                'currentStock':'出库'
            }
            return statusMap[status] || '未知状态'
        },
        // 显示动作面板
        showMoreAction(packageInfo) {
            this.showActSheet = true
            this.packageInfo = packageInfo
            console.log(packageInfo,'packageInfo')
        },

        onCloseActions() {
            this.showActSheet = false
            this.showCalendarPopup = false
        },

        overlayActions() {
            this.showActSheet = false
        },


        // 日历
        showCalendar() {
            this.showCalendarPopup = true
        },
        nextDate() {
            if(this.displayDate == this.formattedDate(new Date())){
                Toast('今天是最后一天了')
                return false
            }
            const [year, month, day] = this.displayDate.split('.').map(Number);
            const currentDate = new Date(year, month - 1, day);
            const date = currentDate.setDate(currentDate.getDate() + 1);
            console.log(date, 'date',currentDate)
            const newDate = this.formattedDate(currentDate);
            this.displayDate = newDate;
            console.log('Next Date:', newDate);

            this.currentDate = this.formattedDateStr(currentDate);
            this.resultList=[]
            this.pageNum=1
            this.loading = false
            this.finished = false
            this.getSelfPickupList()
        },
        prevDate() {
            const [year, month, day] = this.displayDate.split('.').map(Number);
            const currentDate = new Date(year, month - 1, day);
            currentDate.setDate(currentDate.getDate() - 1);
            const newDate = this.formattedDate(currentDate);
            this.displayDate = newDate;
            console.log('Previous Date:', newDate);

            this.currentDate = this.formattedDateStr(currentDate);
            this.resultList=[]
            this.pageNum=1
            this.loading = false
            this.finished = false
            this.getSelfPickupList()
        },
        formattedDate(dateStr) {
            const date = new Date(dateStr);
            const year = date.getFullYear();
            let month = (date.getMonth() + 1).toString().padStart(2, '0');
            let day = date.getDate().toString().padStart(2, '0');
            return `${year}.${month}.${day}`;
        },
        formattedDateStr(dateStr) {
            const date = new Date(dateStr);
            const year = date.getFullYear();
            let month = (date.getMonth() + 1).toString().padStart(2, '0');
            let day = date.getDate().toString().padStart(2, '0');
            return `${year}-${month}-${day}`;
        },

        // 时间戳转换
        formatDate(timestamp) {
            // const timestamp = 1742572800000;
            const date = new Date(timestamp);
            const year = date.getFullYear();
            // 月份从 0 开始计数，所以要加 1
            const month = String(date.getMonth() + 1).padStart(2, '0'); 
            const day = String(date.getDate()).padStart(2, '0');
            const formattedDate = `${year}.${month}.${day}`;
            console.log(formattedDate);
            return formattedDate;
        },
        // 日历选择时间
        onConfirmStockOutCalendar( date) {
            console.log(date,'date---')
            this.displayDate = date
            this.currentDate = date.replaceAll('.', '-')
            // console.log(this.currentDate,'date---')
            this.singleList=[]
            this.resultList=[]
            this.pageNum=1
            this.loading = false
            this.finished = false
            this.getSelfPickupList()
        },


   
        selectFilter(val,e,name){
            this.current=val
        },

        // 单个出库
        toStockOut(item){
            console.log(item, '单个出库')
        },
        // 出库
        toPhotoOut(item){
            console.log(item, '出库')
        },


        // 清空
        clearData(){
            this.selectedRowKeys = []
            this.selectedRows = []
            this.checkAll = false
        },
        // 过滤selectedRows
        filterSelectedRows(list){
            if (this.selectedRowKeys.length > 0 && list.length > 0) {
                // 过滤掉 selectedRowKeys 中存在于 singleList 的元素
                this.selectedRowKeys = this.selectedRowKeys.filter(key => !list.includes(key));
                this.selectedRows = this.selectedRows.filter(row => !list.includes(row.orderId));
            }
        },
        
        // 多选单选全选
        handleCheckboxChange({item, checked}) {
            console.log(item, 'i', checked, 'c')
            const index = this.selectedRowKeys.indexOf(item.orderId)
            console.log(index, 'indes')
            if (item.isChecked === true) {
                if (index === -1) {
                    this.selectedRowKeys.push(item.orderId)
                    this.selectedRows.push(item)
                }
                // this.selectedRowKeys.push(item.orderId)
                // this.selectedRows.push(item)
            } else {
                this.selectedRowKeys.splice(index, 1)
                this.selectedRows.splice(index, 1)
            }
            console.log(this.selectedRowKeys, 'selectedRowKeys')
            this.checkAll = this.selectedRowKeys.length === this.resultList.length
            this.resultList.forEach(ele => {
                if (ele.orderId === item.orderId) {
                    ele.isChecked = checked
                }
            })
        },
        // 标记  选择框  文字
        handlechecked (item, checked) {
            console.log(item, checked, '单选----')
            this.checkAll = this.checked.length === this.resultList.length
            const index = this.selectedRowKeys.indexOf(item.orderId)

            if (checked === true) {
                this.selectedRowKeys.push(item.orderId)
                this.selectedRows.push(item)
            } else {
                console.log(index, 'indesR')
                this.selectedRowKeys.splice(index, 1)
                this.selectedRows.slice(index, 1)
            }
            this.resultList.forEach(ele => {
                if (ele.orderId === item.orderId) {
                    ele.isChecked = checked
                }
            })

        },
        // 全选后面的文字
        onChangeItem (type, item) {
            console.log(type, 'type', 'onChange')
            if (type === '多选') {
                this.checkAll = !this.checkAll
                console.log(this.checked)
                this.handleSelectAll(this.checkAll, !this.select)

            } else {
                // if (this.select && (item.onOffShelvesStatus === false || item.productStock <= 0)) {
                //     return false;
                // }
                // item.status = !item.status;
                // this.handleCheckLogic(item, item.status);
            }
        },
        handleSelectAll(checked, isManageMode) {
            const targetList = this.resultList
            const allCheckedIds = targetList.map(item => item.orderId)
            targetList.forEach(item => { item.isChecked = checked })

            if (checked) {
                this.checked = allCheckedIds;
                this.selectedRows = JSON.parse(JSON.stringify(targetList));
            } else {
                this.checked = [];
                this.checkAll = false;
                this.selectedRows = [];
            }
            this.selectedRowKeys = this.checked;
        },

        // 处理全选
        handleCheckAll(val) {
            console.log(val, '全选按钮')
            const checkAll = val.detail
            const targetList = this.resultList
            const allCheckedIds = targetList.map(item => item.orderId)
            targetList.forEach(item => { item.isChecked = checkAll })
            if (checkAll) {
                this.selectedRows = JSON.parse(JSON.stringify(targetList));
                this.checked = allCheckedIds
            } else {
                this.selectedRows = []
                this.checked = []
            }
            this.selectedRowKeys = this.checked
            console.log(this.resultList, 'resultList')
        },

        // 出入库单个包裹
        submitSinglePackage(item,status,handleType) {
            console.log(item, '单个包裹',status,handleType,this.type)
            const selectedList =[]
            selectedList.push(item.orderId)
            if(handleType=='single'){
                this.singleList = selectedList
                console.log(this.singleList,'singleList')
            }
            Dialog.confirm({
                // title: '标题',
                message: `确定${this.getTipsStatusText(this.type)}${item.orderId}?`,
            })
            .then(() => {
                if(this.type=='await' || this.type=='abnormal' || this.type=='returnAwaitIn'){
                   this.handleInbound(handleType)
                }else if(this.type=='hasIn' || this.type=='returnAwaitOut' ||this.type=='PENDING'||this.type=='currentStock' ){
                    this.handleOutbound(handleType)
                }
                console.log('confirm')
                // Toast('已入库')
            })
            .catch(() => {
                this.singleList=[]
                console.log('cancel')
            });
        },

        // 入库 单个或者批量
        handleInbound(type) {
            console.log(type, '出入库')
            let selectedCount = 0
            const list = this.singleList // 存储单个出入库时选中的包裹
            if(type=='multiple'){
                selectedCount = this.selectedRowKeys.length;
            }
            handleInboundApi({
                orderIdList:type=='single'? this.singleList :this.selectedRowKeys,
                isReturn:this.statusNumber && (this.statusNumber==6 || this.statusNumber==5) ? 1 :0 // 是否退货入库 0=不是 1=是
            }).then(res=>{
                console.log(res,'入库')
                if(res.code==200){
                    if(type=='single'){
                        Toast('已入库')
                        this.filterSelectedRows(list)
                        this.singleList=[]
                    }else{
                        Toast({
                            message: `批量入库${selectedCount}个商品`,
                            duration: 3000
                        });
                        // 使用 setTimeout 确保 Toast 显示后再执行 clearData
                        setTimeout(() => {
                            this.clearData()
                        }, 3000);
                    }
                    this.resultList=[]
                    this.pageNum=1
                    this.loading = false
                    this.finished = false
                    this.getSelfPickupList()
                }
            })
        },
        // 出库
        handleOutbound(type) {
            console.log(type, '出库',this.singleList,this.statusNumber)
            let selectedCount = 0
            const list = this.singleList // 存储单个出入库时选中的包裹
            if(type=='multiple'){
                selectedCount = this.selectedRowKeys.length;
            }
            handleOutboundApi({
                orderIdList:type=='single'? this.singleList :this.selectedRowKeys,
                isReturn:this.statusNumber && (this.statusNumber==6 || this.statusNumber==5) ? 1 :0  // 是否退货入库 0=不是 1=是

            }).then(res=>{
                console.log(res,'出库')
                if(res.code==200){
                    if(type=='single'){
                        Toast('已出库')
                        this.filterSelectedRows(list)
                        this.singleList=[]
                        this.resultList=[]
                        this.pageNum=1
                        this.loading = false
                        this.finished = false
                        this.getSelfPickupList()
                    }else{
                        Toast({
                            message: `批量出库${selectedCount}个商品`,
                            duration: 3000
                        });
                        this.clearData()
                        this.resultList=[]
                        this.pageNum=1
                        this.loading = false
                        this.finished = false
                        this.getSelfPickupList()
                    }
                }
            })
        },
        // 取消出库
        cancelStockOut(info) {
            Dialog.confirm({
                message: `确定${info.orderId}取消出库吗?`,
            })
            .then(() => {
                console.log('confirm')
                this.cancelInOrOut(info)
            })
            .catch(() => {
                // on cancel
            });
        },

        // 取消入库  // 弹窗取消
        onConfirmCancel(type,info) {
            console.log(type, '取消入库',info)
            this.cancelInOrOut(info)
        },

        // 取消出入库    1 入库  4 出库  5 退货入库  6 退货出库 单独的按钮
        cancelInOrOut(info) {
            console.log(info, '取消出入库',this.statusNumber)
            const inOrOut = [2, 6].includes(this.statusNumber) ? 0 : 1;  // 2 4 5 
            cancelSelfPickupApi({
              orderId: info.orderId,
              isReturn:this.statusNumber && (this.statusNumber==6 || this.statusNumber==5) ? 1 :0, // 是否退货入库 0=不是 1=是
              inOrOut:inOrOut, // 入库 0=入库 1=出库
            }).then(res => {
                if (res.code === 200) {
                    Toast('取消成功')
                    // Toast({
                    //     message: `取消${this.getTipsStatusText(info.status)}${info.orderId}`,
                    //     duration: 3000
                    // });
                    this.resultList=[]
                    this.pageNum=1
                    this.loading = false
                    this.finished = false
                    this.getSelfPickupList()
                }
            })
        },
        // 取消退货入库
        cancelReturnStockIn(item) {
            Dialog.confirm({
                // title: '标题',
                message: `确定${item.orderId}取消退货入库吗?`,
            }).then(() => {
                this.cancelInOrOut(item)
            })
            .catch(() => {
                // on cancel
            });
        },

        // 一键出入库
        async allTakeInOrOut(){
            // 如果正在提交，直接返回
            if (this.isSubmiting) {
                return;
            }
            // 标记为正在提交
            this.isSubmiting = true;
            try{
                if(this.selectedRowKeys.length==0){
                    Toast('请选择包裹')
                    return false
                }
                // 所有需要出库的状态
                if(this.type=='hasIn' || this.type=='returnAwaitOut' ||this.type=='PENDING' || this.type=='currentStock'){
                    Toast({
                        message: `批量出库${this.selectedRowKeys.length}个商品`,
                        duration: 3000
                    });
                    this.handleOutbound('multiple')
                }else if(this.type=='await' || this.type=='abnormal' || this.type=='returnAwaitIn'){ // 所有需要入库的状态
                    Toast({
                        message: `批量入库${this.selectedRowKeys.length}个商品`,
                        duration: 3000
                    });
                    this.handleInbound('multiple')
                }
                console.log(this.selectedRowKeys,'selectedRowKeys')
                console.log(this.selectedRows,'selectedRows')
                this.clearData()
                this.getSelfPickupList()
            }catch (error) {
                console.error('操作出错:', error);
            } finally {
                // 无论成功或失败，操作完成后将 isSubmiting 设为 false
                this.isSubmiting = false;
            }
        },

        // 退货出库
        toReturnOut(item){
            console.log(item, '退货出库')
        },

        // 接口
        getSelfPickupList(){
            console.log(this.currentDate,'currentDate')
            if (this.loading || this.finished) return;
            this.loading = true;
            return new Promise((resolve, reject) => {
            // 入库
            getSelfPickupListApi({
              pageNum:this.pageNum,
              pageSize:this.pageSize,
              status:this.statusNumber,
              queryDate:this.currentDate,
            }).then(res=>{
                console.log(res,'入库')
                if(res.code==200){
                    console.log(res.data,'入库')
                    this.total = res.data.total;
                    // this.resultList=res.data.list
                    this.resultList = this.pageNum === 1
                            ? res.data.list
                            : [...this.resultList, ...res.data.list];
                    if(!this.resultList || this.resultList.length==0){
                        this.finished = true
                        this.showBottomBtn = false
                        return
                    }
                    this.resultList.forEach(ele => {
                        this.$set(ele, 'isShow', false)
                        this.$set(ele, 'isChecked', false)
                        if(ele.status){
                            ele.statusText = this.getStatusText(ele.status)
                        }
                    });
                    this.finished = this.resultList.length >= this.total;
                    this.pageNum++;
                resolve(res)
                } else {
                    reject(res)
                }
            }).finally(() => {
                    this.loading = false;
                })
            })
        }
    },

}
</script>
<style lang="scss" scoped>
::v-deep .navBar .van-icon {
    color: #242629 !important;
}
.content {
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    box-sizing: border-box;
    padding-bottom: calc(0rpx + env(safe-area-inset-bottom));
}

.page{
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    box-sizing: border-box;
}
.scroll-content {
    flex: 1;
    height: 1px;
}
.pageTitle{
    padding: 0 48rpx 12rpx 48rpx;
    font-weight: 500;
    font-size: 56rpx;
    text-align: left;
    color: #333;

    span{
        font-weight: 400;
        font-size: 24rpx;
        text-align: left;
        color: #999;
        margin-left: 32rpx;
    }
}
.date-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 16rpx;
    background: #fff;
    border: 1rpx solid #bfbfbf;
    padding: 14rpx 16rpx;
    margin-top: 20rpx;
    margin-left: 48rpx;
    margin-right: 48rpx;
    margin-bottom: 32rpx;

    .date-prev,
    .date-next {
        width: 40rpx;
        height: 40rpx;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .date-display {
        flex: 1;
        text-align: center;
        align-items: center;
        font-size: 32rpx;
        img{
            width: 32rpx;
            height: 32rpx;
            margin-right: 16rpx;
        }
    }
}

// 综合  销量  价格按钮
// .tabsBox {
//     padding: 24rpx 48rpx 0 48rpx;
//     margin-bottom: 32rpx;
//     display: flex;

//     .filter_option {
//         font-size: 24rpx;
//         text-align: center;
//         height: 48rpx;
//         line-height: 48rpx;
//         border-radius: 8rpx;
//         color: #333333;
//         background: #f4f4f4;
//         margin-right: 10px;
//         // padding-left: 9px;
//         // padding-right: 9px;
//         width: 112rpx;
//     }

//     .filter_option_selected:last-child {
//         margin-right: 0px;
//     }

//     .filter_option_selected {
//         border-radius: 8rpx;
//         background: rgb(255, 98, 3, 0.1);
//         color: #ff6203;
//     }
// }

// // 搜索结果的数据统计
// .searchStatistic{
//     height: 64rpx;
//     background: #efefef;
//     color: #333333;
//     font-size: 24rpx;
//     font-weight: 400;
//     letter-spacing: 0;
//     line-height: 64rpx;
//     padding-left: 48rpx;
//     span{
//         color: #FF6203;
//     }
// }

// 搜索结果列表
.expressListBox{
    padding-bottom: 144rpx;
    margin-bottom: 32rpx;
}
::v-deep .van-nav-bar {
    // background-color: #f9f9f9 !important;
    z-index: 999 !important;
  }


// 搜索框的输入框

::v-deep .van-search {
    padding: 0px;
    background: transparent;
    border-radius: 32rpx;
    border: 1rpx solid #ff6202;
    height: 64rpx;
}

::v-deep .van-search--withaction {
    background: transparent;

}

::v-deep .van-search__content {
    background-color: transparent;
    // padding-left: 0px !important;
}

::v-deep .van-search__content--round {}

::v-deep .van-search__action {
    border-radius: 28rpx;
    background: #ff6203;
    font-size: 28rpx;
    color: #ffffff !important;
    height: 56rpx;
    line-height:56rpx;
    margin-right: 10px;
    width: 120rpx;
    text-align: center;
}

::v-deep .van-icon-search {
    color: #888888;
}

.checked-img {
    height: 40rpx;
    width:40rpx;
}
::v-deep .bar-class, .van-submit-bar__bar{
  display: flex;
  justify-content: space-between !important;
  border-top: 1px solid #f9f9f9 !important;
  // padding-top: 20px !important;
}
::v-deep .van-submit-bar__tip {
    color: #FF6203 !important;
    background-color:#FFF9F7 !important;
    padding-left: 24px !important;
    padding-right: 24px !important;
    line-height: 35px !important;

}
::v-deep .van-button--warning {
    background-color: #FF6203;
}
::v-deep .van-empty__image {
    width: 300rpx;
    height: 300rpx;
}
// 动作面版
.van-action-sheet__header {
    font-size: var(--action-sheet-header-font-size,16px);
    font-weight: var(--font-weight-bold,500);
    line-height: var(--action-sheet-header-height,48px);
    text-align: left;
    padding: 0 48rpx !important;
}
.pl24{
    padding-left: 24rpx;
}
.pr24{
    padding-right: 24rpx;
}
// 定义新的类
::v-deep .is-submiting .van-submit-bar__button {
    // 可以根据需求修改样式，例如禁用状态的背景色
    background-color: #cccccc; 
    // 禁用状态的文字颜色
    color: #999999; 
    // 禁用鼠标指针样式
    cursor: not-allowed; 
}
</style>